<template>
    <el-container>
        <el-header height="80px" style="padding: 10px;">
            <!-- 工具/搜索栏 -->
            <div style="padding: 5px; background: #F2F6FC; border-radius: 5px;">
                <div class="topbar">
                    <div class="left-panel">
                    </div>
                    <div class="right-panel">
                        <div class="right-panel-search">
                            <el-date-picker
                            v-model="opTimeRanges"
                            type="daterange"
                            @change="setTime"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            format="yyyy-MM-dd HH:mm:ss"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            :default-time="['00:00:00', '23:59:59']"
                            clearable="">
                            </el-date-picker>
                            <el-input v-model="searchForm.searchText" placeholder="操作描述/操作者" style="width: 200px;"></el-input>
                            <el-button type="primary" icon="el-icon-search" @click="getList()"></el-button>
                            <el-button type="warning" icon="el-icon-refresh" @click="refresh"></el-button>
                        </div>
                    </div>
                </div>
            </div>       
        </el-header>

        <el-main style="padding-left: 10px; padding-right: 10px;">
            <el-card shadow="always" body-style="padding: 0px; min-height: 500px;">
                <el-table
                ref="Table"
                :data="pageResult.list"
                element-loading-text="加载数据中"
                v-loading="loading"
                :header-row-style="{height:45+'px'}"
                :row-style="{height:60+'px'}"
                style="width: 100%; min-height: 450px;"
                :header-cell-style="{background:'#F2F6FC'}">
                    <el-table-column type="expand">
                        <template slot-scope="props">
                            <el-descriptions title="参数详情" :column="1" style="padding: 10px; color: #2b4b6b; ">
                                <el-descriptions-item label="请求方法">{{ props.row.optMethod }}</el-descriptions-item>
                                <el-descriptions-item label="请求参数">{{ props.row.optArgs }}</el-descriptions-item>
                            </el-descriptions>
                        </template>
                    </el-table-column>
                    <el-table-column prop="id"          label="编号"    width="100" ></el-table-column>
                    <el-table-column prop="requestUri"  label="请求路径" ></el-table-column>
                    <el-table-column prop="optMethod"  label="请求方法" ></el-table-column>
                    <el-table-column prop="optDesc"  label="操作描述" ></el-table-column>
                    <el-table-column prop="optUser"  label="操作者" ></el-table-column>
                    <el-table-column prop="optTime"  label="操作时间" ></el-table-column>
                    <template #empty>
                        <el-empty :description="'查无数据'" :image-size="100"></el-empty>
                    </template>
                </el-table>
                <pagination :total="pageResult.total" @page-change="pageChange"></pagination>
            </el-card>
            
        </el-main>

    </el-container>
</template>

<script>

export default {
    data() {
        return {
            opTimeRanges: null,
            searchForm: {
                searchText: '',
                bgnOpTime: null,
                endOpTime: null,
            },
            pageResult: { 
                total: 0,
                pageNum: 1,
                pageSize: 10,
                list: []
            },
            loading: false
        }
    },
    mounted() {       
        // 初始化列表
        this.getList()
    },
    methods: {
        /**
         * @title 获取列表
         */
        async getList() {
            this.loading = true
            let response = await this.$API.optLog.getList(this.searchForm)   
            this.pageResult = response.data
            this.loading = false         
        },

        refresh() {
            this.searchForm.searchText = ''
            this.searchForm.bgnOpTime = null
            this.searchForm.endOpTime = null
            this.searchForm.opType = null
            this.opTimeRanges = null
            this.getList()
        },

        /**
         * @title 更改分页
         */
        pageChange(pageNum, pageSize) {
            this.searchForm.pageNum = pageNum
            this.searchForm.pageSize = pageSize
            this.getList()
        },

        setTime(val) {
            this.searchForm.bgnOpTime = val[0]
            this.searchForm.endOpTime = val[1]
        }
       
    }
}
</script>

<style lang="scss" scoped>
.el-main {
    width: 100%;
    height: 100%;
    padding: 0px;
}
.topbar {
    height: 50px; 
    display: flex;
    justify-content:space-between;
    margin-bottom: 0px;

    .left-panel {
        display: flex;
        align-items: center;
    }
    .right-panel {
        display: flex;
        align-items: center;
    }

    .right-panel-search {display: flex;align-items: center;}

    .right-panel-search > * + * {margin-left:10px;}
}

</style>